package com.dream.keigezhushou.Activity.pop;

import android.content.Context;
import android.view.MotionEvent;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.dream.keigezhushou.R;

import java.util.ArrayList;

/**
 * Created by Administrator on 2017/3/21.
 * 礼物弹出框
 */
public class GiftPopWindow extends DialogBase {

    private Context context;


    private TextView ck1, ck20, ck66, ck99;
    private TextView ckCustom;
    private Button makeSureBtn;
    private ItemClickListener itemClickListener;
    private ArrayList<TextView> dateText;

    //


    /**
     * @param contentView
     * @param context
     * @param width
     * @param height      设置高度
     */
    public GiftPopWindow(final View contentView, final Context context, int width, int height) {
        super(contentView, context, width, height);
        this.context = context;
        dateText = new ArrayList<>();
        ck1 = (TextView) contentView.findViewById(R.id.pop_gift_1);
        ck20 = (TextView) contentView.findViewById(R.id.pop_gift_20);
        ck66 = (TextView) contentView.findViewById(R.id.pop_gift_66);
        ck99 = (TextView) contentView.findViewById(R.id.pop_gift_99);
        ckCustom = (TextView) contentView.findViewById(R.id.pop_gift_custom);
        makeSureBtn=(Button) contentView.findViewById(R.id.pop_gift_makesure);


        dateText.add(ck1);
        dateText.add(ck20);
        dateText.add(ck66);
        dateText.add(ck99);
        ck1.setOnClickListener(new MyListener());
        ck20.setOnClickListener(new MyListener());
        ck66.setOnClickListener(new MyListener());
        ck99.setOnClickListener(new MyListener());


        ckCustom.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (itemClickListener!=null){
                    itemClickListener.onSingDetail(v);
                }
            }
        });


        makeSureBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (itemClickListener!=null){

                    itemClickListener.onClick();
                }

            }
        });
    }


    public void setItemListener(ItemClickListener itemClickListener) {

        this.itemClickListener = itemClickListener;
    }


    private class MyListener implements View.OnClickListener {

        @Override
        public void onClick(View v) {
            for (int i = 0; i < dateText.size(); i++) {
                if (v.getId() == dateText.get(i).getId()) {
                    dateText.get(i).setTextColor(context.getResources().getColor(R.color.color_FF453F));
                    dateText.get(i).setBackgroundResource(R.color.color_E6E6E6);
                    String text = dateText.get(i).getText().toString();
                } else {
                    dateText.get(i).setTextColor(context.getResources().getColor(R.color.color_666666));
                    dateText.get(i).setBackgroundResource(R.color.transparent);
                }
            }
        }

    }


    public interface ItemClickListener {

        public void onClick();

        public void onSingDetail(View view);
    }


}
